package org.point.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.point.common.controller.BaseController;
import org.point.domain.ConvertRuleDetail;
import org.point.service.ConvertRuleDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSONObject;

/**
 * 
 * @ClassName: ConvertRuleDetailController  
 * @Description: TODO(这里用一句话描述这个类的作用)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午9:17:53  
 *
 */
@Controller
@RequestMapping("convertRD")
public class ConvertRuleDetailController extends BaseController {

	@Autowired
	private ConvertRuleDetailService service;
	
	/**
	 * 
	 * @Title: crdlist 
	 * @Description: TODO(这里用一句话描述这个方法的作用) 
	 * @param @param createoper
	 * @param @param currentPage
	 * @param @param response    设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	@RequestMapping(value = "crdlist.do", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public void crdlist(@RequestParam(value = "createoper")String createoper, @RequestParam(value = "currentPage")Integer currentPage, HttpServletResponse response){
		
	}
	
	@RequestMapping(value = "crdinsert.do", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public void crdinsert(@ModelAttribute("ConvertRuleDetail")ConvertRuleDetail record, HttpServletResponse response){
		
	}
	
	/**
	 * 
	 * @Title: editstatus 
	 * @Description: TODO(修改兑换规则明细状态) 
	 * @param @param status
	 * @param @param convertId
	 * @param @param response    设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	@RequestMapping(value = "editstatus.do", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public void editstatus(@RequestParam(value = "status")String status, @RequestParam(value = "convertId")String convertId, HttpServletResponse response){
		
		JSONObject jsonObj = new JSONObject();
		Map<String, Object> map = new HashMap<String, Object>();
		Integer result = 0;
		try {
			if(strOperateUtil.isNullForString(convertId)){
				map.put("convertId", convertId);
				if(strOperateUtil.isNullForString(status)){
					map.put("status", status);
					// result = service.updStatus(map);
					// 修改状态成功
					jsonObj.put("resultMsg", 1);
				} else {
					// 修改状态为null
					jsonObj.put("resultMsg", -2);
				}
			} else {
				// 用户ID为null
				jsonObj.put("resultMsg", -1);
			}
		} catch (Exception e) {
			jsonObj.put("resultMsg", result);
			throw new RuntimeException("修改兑换规则状态", e);
		} finally {
			try {
				feedback(response, jsonObj.toString());
			} catch (Exception e) {
				throw new RuntimeException("网络错误，请联系管理员！", e);
			}
		}
		
	}
	
	/**
	 * 
	 * @Title: editdelflag 
	 * @Description: TODO(修改兑换规则明细删除状态) 
	 * @param @param delflag
	 * @param @param convertId
	 * @param @param response    设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	@RequestMapping(value = "editdelflag.do", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public void editdelflag(@RequestParam(value = "delflag")String delflag, @RequestParam(value = "convertId")String convertId, HttpServletResponse response){
		
		JSONObject jsonObj = new JSONObject();
		Map<String, Object> map = new HashMap<String, Object>();
		Integer result = 0;
		try {
			if(strOperateUtil.isNullForString(convertId)){
				map.put("convertId", convertId);
				if(strOperateUtil.isNullForString(delflag)){
					map.put("delflag", delflag);
					// result = service.updDelflag(map);
					// 修改状态成功
					jsonObj.put("resultMsg", 1);
				} else {
					// 修改状态为null
					jsonObj.put("resultMsg", -2);
				}
			} else {
				// 用户ID为null
				jsonObj.put("resultMsg", -1);
			}
		} catch (Exception e) {
			jsonObj.put("resultMsg", result);
			throw new RuntimeException("修改兑换规则删除状态", e);
		} finally {
			try {
				feedback(response, jsonObj.toString());
			} catch (Exception e) {
				throw new RuntimeException("网络错误，请联系管理员！", e);
			}
		}
		
	}
	
}
